package com.niodata.dp.task.entity;

import com.niodata.dp.task.JobTypeParamSchemasV2;
import java.util.List;
import java.util.function.Consumer;

/**
 * job specification for task.
 */
public class JobInfo {

  private String jobId;
  private String taskId;
  private String pkgId;
  private String jobName;
  private String pkgName;
  private String pkgVersion;
  private String pkgPath;
  private String jobType;
  private String pkgType;
  private String pkgLang;
  private JobNodeStyleInfo nodeStyleInfo;
  private JobParams params;
  private List<JobInfo> depJobs;

  public String getJobId() {
    return jobId;
  }

  public void setJobId(String jobId) {
    this.jobId = jobId;
  }

  public String getTaskId() {
    return taskId;
  }

  public void setTaskId(String taskId) {
    this.taskId = taskId;
  }

  public String getPkgId() {
    return pkgId;
  }

  public void setPkgId(String pkgId) {
    this.pkgId = pkgId;
  }

  public String getJobName() {
    return jobName;
  }

  public void setJobName(String jobName) {
    this.jobName = jobName;
  }

  public String getPkgName() {
    return pkgName;
  }

  public void setPkgName(String pkgName) {
    this.pkgName = pkgName;
  }

  public String getPkgVersion() {
    return pkgVersion;
  }

  public void setPkgVersion(String pkgVersion) {
    this.pkgVersion = pkgVersion;
  }

  public String getPkgPath() {
    return pkgPath;
  }

  public void setPkgPath(String pkgPath) {
    this.pkgPath = pkgPath;
  }

  public String getJobType() {
    return jobType;
  }

  public void setJobType(String jobType) {
    this.jobType = jobType;
  }

  public String getPkgType() {
    return pkgType;
  }

  public void setPkgType(String pkgType) {
    this.pkgType = pkgType;
  }

  public String getPkgLang() {
    return pkgLang;
  }

  public void setPkgLang(String pkgLang) {
    this.pkgLang = pkgLang;
  }

  public JobParams getParams() {
    return params;
  }

  public void setParams(JobParams params) {
    this.params = params;
  }

  /**
   * filter out internal params for web view.
   *
   * @return job params
   */
  public JobParams filterOutInternalParams() {
    JobParams copyParams = new JobParams();
    this.params.getParams().keySet().stream().forEach(new Consumer<String>() {
      @Override
      public void accept(String s) {
        if (JobTypeParamSchemasV2.isInternalParam(s)) {
          return;
        }
        Object value = params.getParam(s);
        if (value != null) {
          copyParams.setParam(s, params.getParam(s).toString());
        } else {
          copyParams.setParam(s, "");
        }
      }
    });
    return copyParams;
  }

  public List<JobInfo> getDepJobs() {
    return depJobs;
  }

  public void setDepJobs(List<JobInfo> depJobs) {
    this.depJobs = depJobs;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    //result = prime * result + ((dependentJob == null) ? 0 : dependentJob.hashCode());
    result = prime * result + ((jobId == null) ? 0 : jobId.hashCode());
    result = prime * result + ((jobName == null) ? 0 : jobName.hashCode());
    result = prime * result + ((jobType == null) ? 0 : jobType.hashCode());
    result = prime * result + ((params == null) ? 0 : params.hashCode());
    result = prime * result + ((pkgId == null) ? 0 : pkgId.hashCode());
    result = prime * result + ((pkgLang == null) ? 0 : pkgLang.hashCode());
    result = prime * result + ((pkgName == null) ? 0 : pkgName.hashCode());
    result = prime * result + ((pkgPath == null) ? 0 : pkgPath.hashCode());
    result = prime * result + ((pkgType == null) ? 0 : pkgType.hashCode());
    result = prime * result + ((pkgVersion == null) ? 0 : pkgVersion.hashCode());
    result = prime * result + ((taskId == null) ? 0 : taskId.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    JobInfo other = (JobInfo) obj;
    if (jobId == null) {
      if (other.jobId != null) {
        return false;
      }
    } else if (!jobId.equals(other.jobId)) {
      return false;
    }
    if (jobName == null) {
      if (other.jobName != null) {
        return false;
      }
    } else if (!jobName.equals(other.jobName)) {
      return false;
    }
    if (jobType == null) {
      if (other.jobType != null) {
        return false;
      }
    } else if (!jobType.equals(other.jobType)) {
      return false;
    }
    if (params == null) {
      if (other.params != null) {
        return false;
      }
    } else if (!params.equals(other.params)) {
      return false;
    }
    if (pkgId == null) {
      if (other.pkgId != null) {
        return false;
      }
    } else if (!pkgId.equals(other.pkgId)) {
      return false;
    }
    if (pkgLang == null) {
      if (other.pkgLang != null) {
        return false;
      }
    } else if (!pkgLang.equals(other.pkgLang)) {
      return false;
    }
    if (pkgName == null) {
      if (other.pkgName != null) {
        return false;
      }
    } else if (!pkgName.equals(other.pkgName)) {
      return false;
    }
    if (pkgPath == null) {
      if (other.pkgPath != null) {
        return false;
      }
    } else if (!pkgPath.equals(other.pkgPath)) {
      return false;
    }
    if (pkgType == null) {
      if (other.pkgType != null) {
        return false;
      }
    } else if (!pkgType.equals(other.pkgType)) {
      return false;
    }
    if (pkgVersion == null) {
      if (other.pkgVersion != null) {
        return false;
      }
    } else if (!pkgVersion.equals(other.pkgVersion)) {
      return false;
    }
    if (taskId == null) {
      if (other.taskId != null) {
        return false;
      }
    } else if (!taskId.equals(other.taskId)) {
      return false;
    }
    return true;
  }

  public JobNodeStyleInfo getNodeStyleInfo() {
    return nodeStyleInfo;
  }

  public void setNodeStyleInfo(JobNodeStyleInfo nodeStyleInfo) {
    this.nodeStyleInfo = nodeStyleInfo;
  }
}
